import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:logger/logger.dart';
import 'package:mmkv/mmkv.dart';
import 'package:musician_flutter/ui/route/route.dart';
import 'package:musician_flutter/ui/theme/theme.dart';

import 'generated/l10n.dart';

import 'generated/l10n.dart';
var logger = Logger();

void main() async {
  await MMKV.initialize();
  runApp(ProviderScope(child: const MyApp()));
}

class MyApp extends ConsumerStatefulWidget {
  const MyApp({super.key});

  @override
  ConsumerState<MyApp> createState() => _MyAppState();
}

class _MyAppState extends ConsumerState<MyApp> {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Flutter Demo',
      localizationsDelegates: const [
        S.delegate,
        GlobalCupertinoLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate
      ],
      supportedLocales: S.delegate.supportedLocales,
      localeResolutionCallback: (locale, supportedLocales) {
        if (locale != null && S.delegate.isSupported(locale)) {
          return locale;
        }
        return const Locale("en");
      },
      theme: AppTheme.myTheme,
      routerConfig: ref.watch(goRouterProvider),
      builder: FlutterSmartDialog.init(),
    );
  }
}

